package app.fugema.shop.main.invoice.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.base.common.netBeanPackage.BaseApiResult;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.viewmodel.BaseViewModel;

import java.util.HashMap;
import java.util.Map;

import app.fugema.shop.http.HttpService;
import app.fugema.shop.main.center.model.PointResultBean;
import app.fugema.shop.main.invoice.model.InvoiceInfoParams;

public class InvoiceVM extends BaseViewModel
{

    public InvoiceVM(@NonNull Application application)
    {
        super(application);
    }


    /**
     * 我的 积分 列表
     * @param userkey
     * @param pn
     * @return
     */
    public MutableLiveData<LiveDataWrapper<PointResultBean>> pointRecord(String userkey, int pn)
    {
        return send(HttpService.getHttpServer().getPointRecord(userkey,pn, 15));
    }

    /**
     * 新增 发票抬头
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> saveInvoiceTitle(InvoiceInfoParams invoiceInfoParams)
    {
        Map<String,Object> mParams = new HashMap<>();
        if(UIUtils.isNotEmpty( invoiceInfoParams.getInvoicetype() ))
        {
            mParams.put("invoicetype", invoiceInfoParams.getInvoicetype() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getInvoicecontext() ))
        {
            mParams.put("invoicecontext", invoiceInfoParams.getInvoicecontext() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getName() ))
        {
            // 湖北汉丹机电有限公司    发票抬头 公司名称
            mParams.put("name", invoiceInfoParams.getName() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getCode() ))
        {
            // 报税 号
            mParams.put("code", invoiceInfoParams.getCode() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getRegisteraddress() ))
        {
            mParams.put("registeraddress", invoiceInfoParams.getRegisteraddress() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getRegisterphone() ))
        {
            mParams.put("registerphone", invoiceInfoParams.getRegisterphone() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getBankname() ))
        {
            mParams.put("bankname", invoiceInfoParams.getBankname() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getBankno() ))
        {
            mParams.put("bankno", invoiceInfoParams.getBankno() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getRealname() ))
        {
            mParams.put("realname", invoiceInfoParams.getRealname() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getCellphone() ))
        {
            mParams.put("cellphone", invoiceInfoParams.getCellphone() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getEmail() ))
        {
            mParams.put("email", invoiceInfoParams.getEmail() );
        }

        if(UIUtils.isNotEmpty( invoiceInfoParams.getRegionid() ))
        {
            mParams.put("regionid", invoiceInfoParams.getRegionid() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getAddress() ))
        {
            mParams.put("address", invoiceInfoParams.getAddress() );
        }
        if(UIUtils.isNotEmpty( invoiceInfoParams.getUserkey() ))
        {
            mParams.put("userkey", invoiceInfoParams.getUserkey() );
        }
        /*
        invoicetype=3&
        invoicecontext=公司&
        name=湖北汉丹机电有限公司&
        code=914206007674415815&
        registeraddress=襄城区虎头山冲1号&
        registerphone=07103059520&
        bankname=湖北银行襄阳分行襄城支行&
        bankno=420602000120020001195&
        realname=刁刁平&
        cellphone=13125043081&
        regionid=26122&
        address=湖北省 长虹路001号
        */
        return send(HttpService.getHttpServer().saveInvoiceTitle(mParams));
    }

    /**
     *
     * @param id
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> deleteInvoiceTitleById(long id, String userKey)
    {
        return send(HttpService.getHttpServer().deleteInvoiceTitle(id,userKey));
    }

    /*
    public MutableLiveData<LiveDataWrapper<SubOrderGoodsBean>> petTypeList() {
        return send(HttpService.getHttpServer().petTypeList());
    }
    */
}
